<?php
namespace App\Services;

use App\Models\consult;
use Illuminate\Support\Facades\Redis;

class InformatonService
{
    public static function informatonShow()
    {
       $data = Consult::where('status',config('setting.system.status'))->orderBy('issue_time',config('setting.system.order'))-> get()->toArray();
       return $data;
    }

    public static function listIndex($id)
    {

        $data = Redis::get($id);
        if (empty($data)){
            $content =  consult::where('id',$id)->get()->toarray();
            $content = json_encode($content);
            consult::where('id',$id)->increment('read');
            Redis::setex($id,60*60*24,$content);
            return json_encode(['code'=>200,'data'=>$content,'msg'=>'ok']);
        }else{
            $data = Redis::get($id);
            consult::where('id',$id)->increment('read');
            $data = json_decode($data,true);
            return json_encode(['code'=>200,'data'=>$data,'msg'=>'ok']);
        }
    }
}
